package bobaini.com.prority_rabbitmq_demo;

import bobaini.com.util.RabbitMqUtils;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;

import java.util.HashMap;
import java.util.Map;

/**
 * ClassName: Product
 * author: bob.ly
 * Version: 1.0.0
 * DateTime: 2021/07/27-09:40:00
 * Description:
 */
public class Product {
    private static final String PRIORITY_NAME = "priority_queue";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();

        Map<String, Object> params = new HashMap();
        params.put("x-max-priority", 10);
        channel.queueDeclare(PRIORITY_NAME, true, false, false, params);

        for (int i = 0; i < 10; i++) {
            String message = "info" + i;
            if (i == 5) {
                AMQP.BasicProperties properties = new
                        AMQP.BasicProperties().builder().priority(5).build();
                channel.basicPublish("", PRIORITY_NAME, properties, message.getBytes());
            } else {
                channel.basicPublish("", PRIORITY_NAME, null, message.getBytes());

            }
        }
    }
}
